package com.aaa.security;

import com.aaa.entity.AuthUser;
import com.aaa.entity.Menu;
import com.aaa.service.impl.AuthUserImpl;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: AuthUserConfigure
 * @Description: TODO
 * @Author: 86139
 * @Date: 2021/7/28 21:47
 * @Version:1.0
 **/
@Component
public class AuthUserConfigure implements UserDetailsService {
    @Resource
    AuthUserImpl backuserService;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("username",s);
//        selectOne
//        获取用户的详细信息
        AuthUser user = backuserService.finByUsername(s);


//        String roles="";
//        if(null !=user){
//
//
//            System.out.println("ROLE_ADMIN,menu,update,delete,add");
//            if(user.getUsername().equals("zhangsan")) {
//                roles="ROLE_ADMIN,menu,update,delete,add";
//            }else if(user.getUsername().equals("222")) {
//                roles="ROLE_TEST,select,update,delete,add";
//            }
//            List<GrantedAuthority> grantedAuthorities = AuthorityUtils.commaSeparatedStringToAuthorityList(roles);
//
//            System.out.println(grantedAuthorities);
////            设置用户权限
//            user.setAuthorities(grantedAuthorities);
//            System.out.println(user);
//        }
        return user;
    }






















}
